package com.qf.controller;

import com.qf.pojo.request.TbFirstPictureReq;
import com.qf.pojo.request.TbPermissionReq;
import com.qf.pojo.response.BaseResponse;
import com.qf.service.TbFirstPictureService;
import com.qf.service.TbPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api("首页图片管理器")
@RestController
@RequestMapping("/first")
public class TbfirstPictureController {
    @Autowired
    TbFirstPictureService tbFirstPictureService;
    @ApiOperation(value = "查询所有图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "当前页显示多少行数据",required = true,dataType = "Integer")
    })
    @GetMapping("/findAll")
    @RequiresPermissions({"FIRST_FINDALL"})
    public BaseResponse findAll(@RequestParam("page") Integer page, @RequestParam("size") Integer size){
        return tbFirstPictureService.findAll(page,size);
    }
    @ApiOperation("修改或新增图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tbFirstPictureReq",value = "图片请求对象",required = true,dataType = "TbFirstPictureReq")
    })
    @PostMapping("/updateOrSave")
    @RequiresPermissions({"FIRST_UPDATEORSAVE"})
    public BaseResponse updateOrSave(@RequestBody TbFirstPictureReq tbFirstPictureReq){
        return tbFirstPictureService.updateOrSave(tbFirstPictureReq);
    }
    @ApiOperation("根据id删除某个图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "map",value = "图片id",required = true,dataType = "Map")
    })
    @DeleteMapping("/deleteById")
    @RequiresPermissions({"FIRST_DELETE"})
    public BaseResponse deleteById(@RequestBody Map map){
        return tbFirstPictureService.deleteById(Integer.valueOf(map.get("pid").toString()));
    }
}
